<template>
  	<div id="app" style="position: static">
    	<transition name="slide-fade" mode="out-in">
      		<router-view v-if="shows" />
      		<div v-else class="jzzs">
        		<div>
          			<van-loading type="spinner" color="#fff" />
        		</div>
        		<div>{{ $t("m.qbljz") }}</div>
      		</div>
    	</transition>
    	
  	</div>
</template>
<script>
	import { identity } from "./api/tron";

	export default {
  		name: "app",
  		data() {
			return {
				shows: false,
				err: "",
				tet: "钱包连接中...",
			};
  		},

  		created() {
    		// this.getRate();
			if (this.$store.state.userWallet) {
				this.getdata();
				this.shows = true;
			}

  		},

  		methods: {
			
    		// resize() {
      		// 	var width = window.innerWidth,
			// 	height = window.innerHeight,
			// 	$wrapper = document.getElementById("app"),
			// 	style = "";
      		// 	if (width < height) {
			// 		// 横屏
			// 		style += "width:" + width + "px;"; // 注意旋转后的宽高切换
			// 		style += "height:" + height + "px;";
      		// 	} else {
			// 		// 竖屏
			// 		style += "width:" + height + "px;";
			// 		style += "height:" + width + "px;";
			// 		style += "transform: rotate(90deg);";
			// 		style += "transform-origin: " + width / 2 + "px " + width / 2 + "px;";
			// 	}
      		// 	$wrapper.style.cssText = style;
    		// },
			// 创建钱包
    		getdata() {
				let datas = {
					trxAddress: this.$store.getters.userWallet,
				};
      			this.$post({
        			url: "wms-wallet/createWallet",
        			data: datas,
					callback: (data) => {
						console.log('创建钱包------------',data)
						this.$nextTick(function () {
							var t = data.data;
							if (t) {
								this.mydatas = data.data;
								this.$store.commit("nameid", this.mydatas.id);
								this.$store.commit("s", this.mydatas);
								setTimeout(() => {
									this.shows = true;
								}, 1000);
							}
						});
					},
				}).catch(() => {
					this.$toast(this.$i18n.t("m.errordata"));
				});
			},
			// 获取汇率
    		getRate() {
      			this.$get({
					url: "oms-ore-pool/get0Rate",
					data: {},
					callback: (data) => {
						this.$nextTick(function () {
							var s = data.data;
							if (s) {
							if (this.dqyy == "en-US") {
								this.$store.commit("ttoc", s.token_usdt);
								this.$store.commit("utoc", s.trx_usdt);
								this.$store.commit("ttou", s.token_trx);
							} else {
								this.$store.commit("ttoc", s.token_cny);
								this.$store.commit("utoc", s.trx_cny);
								this.$store.commit("ttou", s.token_trx);
							}
							}
						});
					},
				}).catch(() => {
					this.$toast(this.$i18n.t("m.errordata"));
				});
			},
			async getInfo(){
				let data = await identity()
				console.log('data-----------------',data)
			}
  		},
  		beforeCreate() {
			var i = 0;
			var a = setInterval(() => {
      			if (typeof window.tronWeb !== "undefined") {
					clearInterval(a);
					// this.getInfo()
					// 获取波场地址
        			identity().then((info) => {
            			if (info.indexOf("T") == 0) {
              				this.$store.commit("userWallet", info);
							setTimeout(() => {
								this.getdata();
							}, 100);
						} else {
							this.$toast("请使用波场地址登录游戏");
						}
					},(e) => {
            			this.$toast(e.message);
          			});
      			}
				if (i > 5) {
					this.shows = true;
				}
      			i++;
    		}, 1000);
  		},
  		computed: {
			dqyy() {
				if (this.$store.getters.language) {
					return this.$store.getters.language;
				} else {
					return "zh-CN";
				}
			},
  		},
  		mounted() {
			if (sessionStorage.getItem("yy")) {
				this.$i18n.locale = sessionStorage.getItem("yy");
			}
			// this.resize()
			// window.addEventListener('resize', this.resize)
			console.log(navigator.userAgent);
			let phone = navigator.userAgent; //设备机型的相关信息
			phone = phone.substring(phone.indexOf("(") + 1, phone.indexOf(";")); //处理信息，输出iphone
			console.log(phone);
			var hrt = document.documentElement.clientHeight; //获取当前可视区域的高度存到hrt变量
			window.onload = function () {
				//在页面整体加载完毕时
				// document.getElementById("app").style.height = hrt + "px"; //把获取到的高度赋值给根div
			};
  		},
  		watch: {
			"$store.getters.language": function (val) {
				//你需要执行的代码
				this.$i18n.locale = val;
			},
			"$store.getters.bjmuiscs": function () {
				//你需要执行的代码
				this.plays();
			},
  		},
	};
</script>

<style>
	/*@import url("./assets/css/xjmain.css");*/
	@import url("./assets/css/tmain.css");
	@import url("./assets/css/font.css");

	#app {
		font-family: "Avenir", Helvetica, Arial, sans-serif;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
		text-align: center;
		color: #2c3e50;
		position: relative;
		min-height: 100vh;
		width: 100%;
		background: url("./assets/timg/qtbg.png") no-repeat;
		background-size: 100% 100%;
	}
	.slide-fade-enter-active {
		transition: all 0.3s ease;
	}
	.slide-fade-leave-active {
		transition: all 0.4s cubic-bezier(1, 1);
	}
	.slide-fade-enter {}
	.slide-fade-leave-to {}

	.van-list {
		text-shadow: 1px 1px 1px #11204a;
	}

	.xuanzhuan {
		transform: rotate(90deg);
		/* transform: translate(200px, 100px) scale(.75, .75) rotate(40deg); */
		transform-origin: 50% 50%;
	}

	.bg {
		background-color: green;
		background-size: 100% 100%;
		background-repeat: no-repeat;
	}

	.jzzs div {
		padding-top: 20%;
		color: #fff;
		font-size: 0.24rem;
	}

	.v-15 {
		margin-top: 12vh;
	}
</style>
